<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Services\ActivityService;
use Session;

class SignUpController extends controller{
    public function islogin($mid){
        if(!$mid){
            $_data = array('code'=>'3x000001','msg'=>'请登录','url'=>env('APP_URL'));
        }else{
            $_data = array('code'=>'2x000001','msg'=>'已登录');
        }

        return response()->json($_data);
    }

    public function list($mid){
        if(!$mid){
            $_data  = array('code'=>'3x000001','msg'=>'请登录','url'=>env('APP_URL'));
        }else{
            $activity = new ActivityService;
            $member_activity_list = $activity->getMemberActivityList($mid);
            if($member_activity_list !== false){
                $_data = array('code'=>'2x000001','list'=>$member_activity_list);
            }else{
                $_data = array('code'=>'4x000001','msg'=>'暂无活动报名');
            }
        }

        return response()->json($_data);
    }
	public function store(){

        $id = intval($_POST['activity']);
        $activity = new ActivityService;
        $info = $activity->getMemberActivityInfo(intval($_POST['member_id']),$id);
        if(!empty($info)){
            $_data = array('3x000002','msg'=>'该活动已报名,请勿重复报名');
        }else{
            date_default_timezone_set('PRC');
            $data = array('member_id'=>intval($_POST['member_id']),'activity_id'=>$id,'add_date'=>date('Y-m-d H:i:s'));
            $res = $activity->insertMemberActivity($data);

            if($res){
                $_data = array('code'=>'2x000001','msg'=>'活动报名成功');
            }else{
                $_data = array('code'=>'4x000001','msg'=>'活动报名失败');
            }
        }

		return response()->json($_data);
	}
}